<template>
  <div class="content">
    <div id="table-1">
      <div class="innertitle">1.本底值检测:</div>
      <div class="tip-30">
        <el-radio v-model="form1.backgroundFormula" :label="1" data-must="1"
          >不扣除本底处理公式：</el-radio
        ><i>$D = K · \overline m$</i>
        <el-radio
          style="margin-left: 50px"
          v-model="form1.backgroundFormula"
          :label="2"
          data-must="1"
          >扣除本底处理公式：</el-radio
        ><i>$D = K · (M_{max} - C_{min})$</i>
      </div>

      <table
        border="1"
        cellspacing="0"
        cellpadding="0"
        align="center"
        style="width: 100%"
      >
        <tr>
          <td colspan="5">
            检测条件
            <!-- （<el-radio v-model="form1.exposureType" :label="1">手动</el-radio>
            <el-radio v-model="form1.exposureType" :label="2">自动</el-radio>） -->
          </td>
          <td colspan="9">检测用散射模体</td>
        </tr>
        <tr>
          <td colspan="5">
            <div>
              相应时间修正系数：<el-input v-model="form1.timeCoefficient" class="input-line" />；
              转换因子: <el-input v-model="form1.convertCalibrationFactor" class="input-line" />；
              检测源活度: <el-input v-model="form1.sourceActivity" class="input-line" />mCi；
            </div>

            <el-input v-model="form1.tubeVoltage" class="input-line" />kV
            <el-input v-model="form1.tubeCurrent" class="input-line" />
            <el-radio-group v-model="form1.tubeCurrentUnit" class="split-radio">
              <el-radio :label="0">mA</el-radio>
              <span class="split">/</span>
              <el-radio :label="1">μA</el-radio>
              <span class="split">/</span>
              <el-radio :label="2">mAs</el-radio>
            </el-radio-group>
            <el-input v-model="form1.presets" data-cusValidate="text" class="input-line" />s
            <!-- <div style="margin-top: 0px;" v-if="basicForm.basicInfo.isHeader || (basicForm.protectionDetectionVo && basicForm.protectionDetectionVo.basicInfo.isHeader)">
              头颅侧位方向:
              <el-select class="dir-select" style="width: 100px;" v-model="form1.headLateralDirection">
                <el-option label="东" value="东"></el-option>
                <el-option label="南" value="南"></el-option>
                <el-option label="西" value="西"></el-option>
                <el-option label="北" value="北"></el-option>
                <el-option label="东南" value="东南"></el-option>
                <el-option label="西南" value="西南"></el-option>
                <el-option label="东北" value="东北"></el-option>
                <el-option label="西北" value="西北"></el-option>
              </el-select>；
              校准因子：
              <el-input v-model="form1.headLateralCalibrationFactor" class="input-line result" disabled />
              <div>
                头颅侧位检测条件:
                <el-input v-model="form1.headLateralTubeVoltage" class="input-line" />kV
                <el-input v-model="form1.headLateralTubeCurrent" class="input-line" />
                <el-radio-group v-model="form1.headLateralTubeCurrentUnit" class="split-radio">
                  <el-radio :label="0">mA</el-radio>
                  <span class="split">/</span>
                  <el-radio :label="1">μA</el-radio>
                </el-radio-group>
                <el-input v-model="form1.headLateralPresets" data-cusValidate="text" class="input-line" />s
              </div>
            </div> -->
          </td>
          <td colspan="9">
            <el-checkbox v-model="form1.standardModel">标准水模</el-checkbox>
            <el-checkbox v-model="form1.standardModelAnd_1_5mm"
              >标准水模+1.5mm铜板</el-checkbox
            >
            <el-checkbox v-model="form1.ctHeadModel">CT头模</el-checkbox>
            <el-checkbox v-model="form1.ctBodyModel">CT体模</el-checkbox>
            <el-checkbox v-model="form1.pmma_6cm">6cm PMMA</el-checkbox>
            <el-checkbox v-model="form1.workpiece">工件</el-checkbox>
          </td>
        </tr>
      </table>
      <table
        border="1"
        cellspacing="0"
        cellpadding="0"
        align="center"
        style="width: 100%"
      >
        <tr>
          <td colspan="10">
            本底测量值C<br />
            <el-radio-group v-model="form1.backgroundValueUnit" class="split-radio">
              <el-radio :label="1">nSv/h</el-radio>
              <el-radio :label="2">μSv/h</el-radio>
              <el-radio :label="3">mSv/h</el-radio>
            </el-radio-group>
          </td>
          <td style="width: 100px">本底校准因子</td>
          <td style="width: 100px">
            修正后本底平均值B,μSv/h
          </td>
          <td style="width: 100px">
            修正后本底范围,μSv/h
          </td>
          <td>校准因子K</td>
        </tr>
        <tr>
          <td><el-input v-model="form1.background_1" /></td>
          <td><el-input v-model="form1.background_2" /></td>
          <td><el-input v-model="form1.background_3" /></td>
          <td><el-input v-model="form1.background_4" /></td>
          <td><el-input v-model="form1.background_5" /></td>
          <td><el-input v-model="form1.background_6" /></td>
          <td><el-input v-model="form1.background_7" /></td>
          <td><el-input v-model="form1.background_8" /></td>
          <td><el-input v-model="form1.background_9" /></td>
          <td><el-input v-model="form1.background_10" /></td>
          <td class="result">
            <el-input v-model="form1.backgroundCalibrationFactor" disabled />
          </td>
          <td class="result">
            <el-input v-model="form1.backgroundCountAverage" disabled />
          </td>
          <td class="result">
            <el-input v-model="form1.backgroundCountRadius" disabled />
          </td>
          <td class="result">
            <el-input v-model="form1.calibrationFactor" disabled />
          </td>
        </tr>
      </table>
    </div>

    <div id="table-4">
      <div class="innertitle">
        2.环境γ辐射剂量率检测:
      </div>
      <div>
        <!-- 仪器校准因子：<el-input class="input-line" v-model="form4.calibrationFactor" />； -->
        周围剂量当量率和空气比释动能率的转换因子：<el-input class="input-line" v-model="form4.convertCalibrationFactor" />；
      </div>
      <!-- <div style="margin-top: 10px">
        是否扣除宇宙射线响应值：
        <el-radio-group v-model="form4.responseValueFormula" class="split-radio">
          <el-radio :label="1">不扣除</el-radio>
          <el-radio :label="2">扣除</el-radio>
        </el-radio-group>；
        经度：<el-input class="input-line" v-model="form4.lon" />；
        纬度：<el-input class="input-line" v-model="form4.lat" />；
        海拔：<el-input class="input-line" v-model="form4.altitude" />；
        宇宙射线响应值：<el-input class="input-line" v-model="form4.responseValue" />；
      </div> -->
      <table
        border="1"
        cellspacing="0"
        cellpadding="0"
        align="center"
        style="width: 100%"
      >
        <tr>
          <td style="width: 50px" rowspan="2">序号</td>
          <td style="width: 220px" rowspan="2">关注点</td>
          <td colspan="11">环境γ辐射剂量率检测结果</td>
          <td style="width: 100px;" rowspan="2">
            检测结果
          </td>
        </tr>
        <tr>
          <td colspan="10">读数</td>
          <td>单位</td>
        </tr>
        <tr v-for="(item, index) in form4.baseLocations" :key="index + 200">
          <td>
            <el-input v-model="item.serial" disabled />
          </td>
          <td>
            <el-input v-model="item.positionName" data-cusValidate="text" />
          </td>
          <td style="width: 60px" v-for="idx in 10">
            <el-input v-model="item[`readoutValue_${idx}`]" />
          </td>
          <td>
            <el-radio-group v-model="item[`readoutValueUnit`]" class="split-radio">
              <el-radio :label="1">nSv/h</el-radio>
              <el-radio :label="2">μSv/h</el-radio>
              <el-radio :label="3">mSv/h</el-radio>
            </el-radio-group>
          </td>
          <td>
            <el-input v-model="item[`resultValue`]" data-cusValidate="text" />
          </td>
        </tr>
      </table>
    </div>

    <div id="table-2">
      <div class="innertitle">
        3.辐射剂量率检测:
      </div>
      <div>
        是否扣除宇宙射线响应值：
        <el-radio-group v-model="form2.responseValueFormula" class="split-radio">
          <el-radio :label="1">不扣除</el-radio>
          <el-radio :label="2">扣除</el-radio>
        </el-radio-group>；
        经度：<el-input class="input-line" v-model="form2.lon" />；
        纬度：<el-input class="input-line" v-model="form2.lat" />；
        海拔：<el-input class="input-line" v-model="form2.altitude" />；
        宇宙射线响应值：<el-input class="input-line" v-model="form2.responseValue" />；
      </div>
      <table
        border="1"
        cellspacing="0"
        cellpadding="0"
        align="center"
        style="width: 100%"
      >
        <tr>
          <td style="width: 50px" rowspan="3">序号</td>
          <td style="width: 220px" rowspan="3">关注点</td>
          <td style="width: 60px" rowspan="3">状态</td>
          <td colspan="12">
            辐射剂量率检测结果
          </td>
          <td style="width: 150px;" rowspan="3">
            检测结果<br/>
            (修正值±标准差)
          </td>
          <td rowspan="3" style="width: 180px">备注</td>
        </tr>
        <tr>
          <td colspan="10">读数</td>
          <td rowspan="2">单位</td>
          <td rowspan="2">修正值</td>
        </tr>
        <tr>
          <td>1</td>
          <td>2</td>
          <td>3</td>
          <td>4</td>
          <td>5</td>
          <td>6</td>
          <td>7</td>
          <td>8</td>
          <td>9</td>
          <td>10</td>
        </tr>
        <tr v-for="index in form2.baseLocations.length * 2" :key="index">
          <td :rowspan="index % 2 == 1 ? 2 : 1" v-if="index % 2 == 1">
            <el-input v-model="form2.baseLocations[(index - 1) / 2].serial" disabled />
          </td>
          <td :rowspan="index % 2 == 1 ? 2 : 1" v-if="index % 2 == 1">
            <el-input v-model="form2.baseLocations[(index - 1) / 2].positionName" data-cusValidate="text" />
          </td>
          <td>
            <span v-if="index % 2 == 1">未出束</span>
            <span v-if="index % 2 == 0">出束</span>
          </td>
          <td style="width: 60px" v-for="idx in 10" :key="idx">
            <template v-if="index % 2 == 1">
              <el-input v-model="form2.baseLocations[(index - 1) / 2][`readoutValue_${idx}`]" />
            </template>
            <template v-if="index % 2 == 0">
              <el-input v-model="form2.baseLocations[(index - 2) / 2][`readoutValue_${idx}_n`]" />
            </template>
          </td>
          <td>
            <template v-if="index % 2 == 1">
              <el-radio-group v-model="form2.baseLocations[(index - 1) / 2][`readoutValueUnit`]" class="split-radio">
                <el-radio :label="1">nSv/h</el-radio>
                <el-radio :label="2">μSv/h</el-radio>
                <el-radio :label="3">mSv/h</el-radio>
              </el-radio-group>
            </template>
            <template v-if="index % 2 == 0">
              <el-radio-group v-model="form2.baseLocations[(index - 2) / 2][`readoutValueUnit_n`]" class="split-radio">
                <el-radio :label="1">nSv/h</el-radio>
                <el-radio :label="2">μSv/h</el-radio>
                <el-radio :label="3">mSv/h</el-radio>
              </el-radio-group>
            </template>
          </td>
          <td style="width: 80px">
            <template v-if="index % 2 == 1">
              <el-input v-model="form2.baseLocations[(index - 1) / 2][`correctedValue`]" />
            </template>
            <template v-if="index % 2 == 0">
              <el-input v-model="form2.baseLocations[(index - 2) / 2][`correctedValue_n`]" />
            </template>
          </td>
          <td style="width: 80px">
            <template v-if="index % 2 == 1">
              <el-input v-model="form2.baseLocations[(index - 1) / 2][`resultValue`]" data-cusValidate="text" />
            </template>
            <template v-if="index % 2 == 0">
              <el-input v-model="form2.baseLocations[(index - 2) / 2][`resultValue_n`]" data-cusValidate="text" />
            </template>
          </td>
          <td>
            <template v-if="index % 2 == 1">
              <el-autocomplete
                data-cusValidate="text"
                v-model="form2.baseLocations[(index - 1) / 2]['orientation']"
                :fetch-suggestions="(queryString, cb) => {
                  cb([
                    { value: '土层,人员无法到达' },
                    { value: '临空,人员无法到达' },
                    { value: '无建筑,人员无法到达' },
                  ])
                }"
                @select="submitTestForm(2)"
                placeholder=""
                :popper-append-to-body="false"
              ></el-autocomplete>
            </template>
            <template v-if="index % 2 == 0">
              <el-autocomplete
                data-cusValidate="text"
                v-model="form2.baseLocations[(index - 2) / 2]['orientation_n']"
                :fetch-suggestions="(queryString, cb) => {
                  cb([
                    { value: '土层,人员无法到达' },
                    { value: '临空,人员无法到达' },
                    { value: '无建筑,人员无法到达' },
                  ])
                }"
                @select="submitTestForm(2)"
                placeholder=""
                :popper-append-to-body="false"
              ></el-autocomplete>
            </template>
          </td>
        </tr>
        <tr v-for="index in form2.detectionLocations.length * 2" :key="index + 100">
          <td :rowspan="index % 2 == 1 ? 2 : 1" v-if="index % 2 == 1">
            <el-input v-model="form2.detectionLocations[(index - 1) / 2].serial" disabled />
          </td>
          <td :rowspan="index % 2 == 1 ? 2 : 1" v-if="index % 2 == 1">
            <el-input v-model="form2.detectionLocations[(index - 1) / 2].positionName" data-cusValidate="text" />
          </td>
          <td>
            <span v-if="index % 2 == 1">未出束</span>
            <span v-if="index % 2 == 0">出束</span>
          </td>
          <td style="width: 60px" v-for="idx in 10" :key="idx + 100">
            <template v-if="index % 2 == 1">
              <el-input v-model="form2.detectionLocations[(index - 1) / 2][`readoutValue_${idx}`]" />
            </template>
            <template v-if="index % 2 == 0">
              <el-input v-model="form2.detectionLocations[(index - 2) / 2][`readoutValue_${idx}_n`]" />
            </template>
          </td>
          <td>
            <template v-if="index % 2 == 1">
              <el-radio-group v-model="form2.detectionLocations[(index - 1) / 2][`readoutValueUnit`]" class="split-radio">
                <el-radio :label="1">nSv/h</el-radio>
                <el-radio :label="2">μSv/h</el-radio>
                <el-radio :label="3">mSv/h</el-radio>
              </el-radio-group>
            </template>
            <template v-if="index % 2 == 0">
              <el-radio-group v-model="form2.detectionLocations[(index - 2) / 2][`readoutValueUnit_n`]" class="split-radio">
                <el-radio :label="1">nSv/h</el-radio>
                <el-radio :label="2">μSv/h</el-radio>
                <el-radio :label="3">mSv/h</el-radio>
              </el-radio-group>
            </template>
          </td>
          <td style="width: 80px">
            <template v-if="index % 2 == 1">
              <el-input v-model="form2.detectionLocations[(index - 1) / 2][`correctedValue`]" />
            </template>
            <template v-if="index % 2 == 0">
              <el-input v-model="form2.detectionLocations[(index - 2) / 2][`correctedValue_n`]" />
            </template>
          </td>
          <td style="width: 80px">
            <template v-if="index % 2 == 1">
              <el-input v-model="form2.detectionLocations[(index - 1) / 2][`resultValue`]" data-cusValidate="text" />
            </template>
            <template v-if="index % 2 == 0">
              <el-input v-model="form2.detectionLocations[(index - 2) / 2][`resultValue_n`]" data-cusValidate="text" />
            </template>
          </td>
          <td>
            <template v-if="index % 2 == 1">
              <el-autocomplete
                data-cusValidate="text"
                v-model="form2.detectionLocations[(index - 1) / 2]['orientation']"
                :fetch-suggestions="(queryString, cb) => {
                  cb([
                    { value: '土层,人员无法到达' },
                    { value: '临空,人员无法到达' },
                    { value: '无建筑,人员无法到达' },
                  ])
                }"
                @select="submitTestForm(2)"
                placeholder=""
                :popper-append-to-body="false"
              ></el-autocomplete>
            </template>
            <template v-if="index % 2 == 0">
              <el-autocomplete
                data-cusValidate="text"
                v-model="form2.detectionLocations[(index - 2) / 2]['orientation_n']"
                :fetch-suggestions="(queryString, cb) => {
                  cb([
                    { value: '土层,人员无法到达' },
                    { value: '临空,人员无法到达' },
                    { value: '无建筑,人员无法到达' },
                  ])
                }"
                @select="submitTestForm(2)"
                placeholder=""
                :popper-append-to-body="false"
              ></el-autocomplete>
            </template>
          </td>
        </tr>
        <tr>
          <td colspan="17">
            <span
              style="
                display: inline-block;
                width: 50px;
                padding: 2px 0;
                border: 1px solid #ccc;
                color: #888;
                border-radius: 2px;
                cursor: pointer;
                position: relative;
                z-index: 999;
              "
              @click="handleClickDetectionLocation('delete')"
              >-</span
            >
            <span
              style="
                display: inline-block;
                width: 50px;
                padding: 2px 0;
                border: 1px solid #ccc;
                margin-left: 10px;
                color: #888;
                border-radius: 2px;
                cursor: pointer;
                position: relative;
                z-index: 999;
              "
              @click="handleClickDetectionLocation('add')"
              >+</span
            >
          </td>
        </tr>
      </table>
    </div>

    <div id="table-3">
      <div class="innertitle">4.工作场所放射防护检测位置示意图：</div>
    </div>

    <div id="table-5">
      <div class="innertitle" style="margin: 12px 0">
        <el-button
          style="float: right"
          icon="el-icon-refresh"
          size="mini"
          @click="handleOpenDragCanvas()"
          >设计平面图</el-button
        >
      </div>
      <div class="imageUpload">
        <div>
          <imageUpload
            :limit="1"
            :isShowTip="false"
            v-model="form.recordOssId"
            @input="handleChangeImage"
          />
          <div style="text-align: center;">原始记录点位图</div>
        </div>
        <div style="margin-left: 50px">
          <imageUpload
            :limit="1"
            :isShowTip="false"
            v-model="form.ossId"
            @input="handleChangeImage"
          />
          <div style="text-align: center;">报告点位图</div>
        </div>
      </div>

      <!-- <div class="tip-30">
          有关说明:<br/>
          1、本底校准值=本底读出值x校准因子;<br/>
          2、未扣除本底值情况下:检测结果=读出值平均值x校准因子，扣除本底值情况下: 检测结果=(读出值平均值-本底读出值)x校准因子x相应时间修正系数:<br/>
          3、X射线设备机房的防护检测应在巡测的基础上，对关注点的局部屏蔽和缝隙进行重点检测。关注点应包括:四面墙体、地板、顶棚、机房门、操作门、观察窗、采光窗\窗体、传片箱、管线口、工作人员操作位等。
        </div> -->
    </div>

    <el-dialog
      :title="operType == 'add' ? '选择添加的点位类型' : '选择删除的点位类型'"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-dialogDrag="true"
      @open="handleDialogOpen"
      @close="handleDialogClosed"
    >
      <div style="display: flex; align-items: center">
        <span style="width: 100px; white-space: nowrap">检测位置类型：</span>
        <el-select
          style="width: 100px"
          v-model="detectionLocationType"
          placeholder="请选择"
          @change="handleDetectionLocationTypeChange"
        >
          <el-option
            v-for="item in pointTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-select
          style="width: 250px"
          v-model="groupNumber"
          placeholder="请选择"
          v-if="operType == 'delete'"
        >
          <template v-for="(item, index) in groupNumberList">
            <el-option
              :key="index"
              :label="item.label"
              :value="item.value"
              v-if="containsGroup && containsGroup.includes(item.value)"
            ></el-option>
          </template>

          <!-- <el-option label="②" :value="2" v-if="containsGroup.includes(2)"></el-option>
            <el-option label="③" :value="3" v-if="containsGroup.includes(3)"></el-option>
            <el-option label="④" :value="4" v-if="containsGroup.includes(4)"></el-option>
            <el-option label="⑤" :value="5" v-if="containsGroup.includes(5)"></el-option>
            <el-option label="⑥" :value="6" v-if="containsGroup.includes(6)"></el-option>
            <el-option label="⑦" :value="7" v-if="containsGroup.includes(7)"></el-option>
            <el-option label="⑧" :value="8" v-if="containsGroup.includes(8)"></el-option>
            <el-option label="⑨" :value="9" v-if="containsGroup.includes(9)"></el-option> -->
        </el-select>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleOperDetectionLocationRow"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <DragCanvas ref="dragCanvasRefs" @confirm="handleConfirmDrag" />
  </div>
</template>

<script>
import {
  getInfoById26,
  background,
  protection,
  defensePosition,
  protectionGama,
  saveInfo,
  getPointType,
  getDetectionLocationRow,
} from "@/api/testItem/item26";
import DragCanvas from "../dragCanvas.vue";

export default {
  name: "testItem26",
  dicts: ["protection_condition"],
  components: { DragCanvas },
  data() {
    return {
      protectionShow: false,
      readoutList: [
        {
          id: 1,
          label: "mSv/h",
          value: 1,
        },
        {
          id: 2,
          label: "μSv/h",
          value: 2,
        },
      ],
      otherTypeLists: [
        {
          id: 1,
          label: "普通模式",
          value: 1,
        },
        {
          id: 2,
          label: "DBT",
          value: 2,
        },
      ],
      // tab切换通用数据
      form: {},
      // 表单-1.本底值检测
      form1: {},
      // 表单-2、周围作场所辐射防护测
      form2: {
        baseLocations: [],
        detectionLocations: [],
      },
      form3: {
        protectiveDoor: [],
        controlProtectiveDoor: [],
      },
      form4: {
        baseLocations: [],
      },
      fileList: [],
      showImageUpload: false,
      itemsId: null,
      operType: "add",
      dialogVisible: false,
      pointTypeList: [],
      groupNumberList: [
        { label: "①", value: 1, text: "①" },
        { label: "②", value: 2, text: "②" },
        { label: "③", value: 3, text: "③" },
        { label: "④", value: 4, text: "④" },
        { label: "⑤", value: 5, text: "⑤" },
        { label: "⑥", value: 6, text: "⑥" },
        { label: "⑦", value: 7, text: "⑦" },
        { label: "⑧", value: 8, text: "⑧" },
        { label: "⑨", value: 9, text: "⑨" },
        { label: "⑩", value: 10, text: "⑩" },
        { label: "⑪", value: 11, text: "⑪" },
        { label: "⑫", value: 12, text: "⑫" },
        { label: "⑬", value: 13, text: "⑬" },
        { label: "⑭", value: 14, text: "⑭" },
        { label: "⑮", value: 15, text: "⑮" },
      ],
      detectionLocationType: 1,
      groupNumber: "",
      containsGroup: [],
    };
  },
  props: {
    // tab栏
    activeNameEquipment: {
      type: String,
      default: "0",
    },
    // 基本信息数据
    basicForm: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  watch: {
    activeNameEquipment: {
      handler(val) {
        let _this = this;
        this.$nextTick(() => {
          // 02-直接荧光屏透视设备专用检测项目
          // 获取详情
          if (!this.basicForm.protectionDetectionVo?.taskDetectionEquipmentResultId) return;
          getInfoById26(
            this.basicForm.protectionDetectionVo.taskDetectionEquipmentResultId
          )
            .then((response) => {
              let { schematicImage, recordOssId, imageJson } = response.data;
              this.form.imageJson = imageJson || "";
              this.itemsId = response.data?.itemsId;
              // 1.本底值检测
              this.form1 = response.data?.detectionBackgroundValue || {};
              this.form1.backgroundFormula = this.form1.backgroundFormula || 1;
              // 2.周围工作场所辐射防护检测
              this.form2 = response.data?.detectionProtection || {};
              // this.form2.positionName_1 = this.form2.positionName_1 || '放射工作人员操作位'
              // this.form2.positionName_2 = this.form2.positionName_2 || '隔室铅玻璃观察窗中部外30cm处'
              // this.form2.positionName_3 = this.form2.positionName_3 || '隔室铅玻璃观察窗上缝外30cm处'
              // this.form2.positionName_4 = this.form2.positionName_4 || '隔室铅玻璃观察窗下缝外30cm处'
              // this.form2.positionName_5 = this.form2.positionName_5 || '隔室铅玻璃观察窗左缝外30cm处'
              // this.form2.positionName_6 = this.form2.positionName_6 || '隔室铅玻璃观察窗右缝外30cm处'
              // this.form2.positionName_7 = this.form2.positionName_7 || '防护门①中部外30cm处'
              // this.form2.positionName_8 = this.form2.positionName_8 || '防护门①上缝外30cm处'
              // this.form2.positionName_9 = this.form2.positionName_9 || '防护门①下缝外30cm处'
              // this.form2.positionName_10 = this.form2.positionName_10 || '防护门①左缝外30cm处'
              // this.form2.positionName_11 = this.form2.positionName_11 || '防护门①右缝外30cm处'
              // this.form2.positionName_12 = this.form2.positionName_12 || '防护门①锁眼/栓外30cm处'
              // this.form2.positionName_13 = this.form2.positionName_13 || '防护门②中缝外30cm处'
              // this.form2.positionName_14 = this.form2.positionName_14 || '防护门②上缝外30cm处'
              // this.form2.positionName_15 = this.form2.positionName_15 || '防护门②下缝外30cm处'
              // this.form2.positionName_16 = this.form2.positionName_16 || '防护门②左缝外30cm处'
              // this.form2.positionName_17 = this.form2.positionName_17 || '防护门②右缝外30cm处'
              // this.form2.positionName_18 = this.form2.positionName_18 || '防护门②锁眼/栓外30cm处'
              // this.form2.positionName_19 = this.form2.positionName_19 || '防护门②中缝（对开）外30cm处'
              // this.form2.positionName_20 = this.form2.positionName_20 || '机房东墙外30cm处'
              // this.form2.positionName_21 = this.form2.positionName_21 || '机房南墙外30cm处'
              // this.form2.positionName_22 = this.form2.positionName_22 || '机房西墙外30cm处'
              // this.form2.positionName_23 = this.form2.positionName_23 || '机房北墙外30cm处'
              // this.form2.positionName_24 = this.form2.positionName_24 || '机房楼上距地面50cm处'
              // this.form2.positionName_25 = this.form2.positionName_25 || '机房楼上距地面100cm处'
              // this.form2.positionName_26 = this.form2.positionName_26 || '机房楼下距地面170cm处'
              // this.form2.positionName_27 = this.form2.positionName_27 || '穿墙管线外30cm处'
              this.form2.baseLocations = this.form2.baseLocations || [];
              this.form2.detectionLocations = this.form2.detectionLocations || [];
              this.form2.detectionLocations.sort(
                (a, b) =>
                  a.positionType - b.positionType ||
                  a.groupNumber - b.groupNumber
              );
              // 3
              this.form3 = response.data?.defensePosition || {};
              this.form3.protectiveDoor =
                this.form3.protectiveDoor?.split(",") || [];
              this.form3.controlProtectiveDoor =
                this.form3.controlProtectiveDoor?.split(",") || [];
              // 4
              this.form4 = response.data?.detectionProtectionGama || {};
              this.form4.baseLocations = this.form4.baseLocations || [];
              const len = this.form4.baseLocations.length;
              if (len < 27) {
                for (let i = 0; i < 27 - len; i++) {
                  this.form4.baseLocations.push({});
                }
              }
              // 3.获取图片
              this.form.ossId = schematicImage;
              this.form.recordOssId = recordOssId;
              this.showImageUpload = true;

              // 绑定请求
              this.bindMethod();
            })
            .then()
            .catch((response) => {
              this.$emit("loadingchange", true);
            });
        });
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    submitTestForm(index) {
      console.log("提交检测项", index);
      this.$emit("loadingchange", true); /* 说明绑定成功 */
      if (index === "form") {
        this.form.itemsId = this.itemsId;
      } else {
        this[`form${index}`].itemsId = this.itemsId;
      }
      switch (index) {
        // 1.DAS动态范围。DAS对比灵敏度 伪影
        case 1:
          background(this.form1).then((response) => {
            // this.$modal.msgSuccess("保存成功");
            response.data ? (this.form1 = response.data) : "";
            this.$emit("loadingchange", false);
            this.submitTestForm(2);
          });
          break;
        case 2:
          const data2 = JSON.parse(JSON.stringify(this.form2));
          data2.itemsId = this.itemsId;
          protection(data2).then((response) => {
            // this.$modal.msgSuccess("保存成功");
            response.data ? (this.form2 = response.data) : "";
            this.$emit("loadingchange", false);
          });
          break;
        case 4:
          const data4 = JSON.parse(JSON.stringify(this.form4));
          data4.itemsId = this.itemsId;
          protectionGama(data4).then((response) => {
            // this.$modal.msgSuccess("保存成功");
            response.data ? (this.form4 = response.data) : "";
            this.form4.baseLocations = this.form4.baseLocations || [];
            const len = this.form4.baseLocations.length;
            if (len < 27) {
              for (let i = 0; i < 27 - len; i++) {
                this.form4.baseLocations.push({});
              }
            }
            this.$emit("loadingchange", false);
          });
          break;
        case 3:
          const data = JSON.parse(JSON.stringify(this.form3));
          data.protectiveDoor = data.protectiveDoor.join(",");
          data.controlProtectiveDoor = data.controlProtectiveDoor.join(",");
          defensePosition(data).then((response) => {
            // this.$modal.msgSuccess("保存成功");
            response.data ? (this.form3 = response.data) : "";
            this.form3.protectiveDoor =
              this.form3.protectiveDoor?.split(",") || [];
            this.form3.controlProtectiveDoor =
              this.form3.controlProtectiveDoor?.split(",") || [];
            this.$emit("loadingchange", false);
          });
          break;
        case "form":
          // 其余信息
          let { ossId, recordOssId, itemsId, imageJson } = this.form;
          // let {resultId} = this.basicForm
          // return
          saveInfo({ ossId, recordOssId, itemsId, imageJson }).then(
            (response) => {
              this.$emit("loadingchange", false);
            }
          );
          break;
      }
    },
    // 绑定方法
    bindMethod() {
      let itemsLength = 4;
      for (let index = 0; index < itemsLength; index++) {
        let tableInputs = document
          .getElementById(`table-${index + 1}`)
          ?.getElementsByTagName("input");
        this.$nextTick(() => {
          Array.from(tableInputs).forEach((element) => {
            this.bind(element, () => {
              this.submitTestForm(index + 1);
            });
          });
        });
      }
    },
    handleClickDetectionLocation(type) {
      this.operType = type;
      this.dialogVisible = true;
      if (this.pointTypeList.length <= 0) {
        getPointType()
          .then((res) => {
            this.pointTypeList = res.data || [];
          })
          .catch(() => {});
      }
    },
    handleOperDetectionLocationRow() {
      if (this.operType == "add") {
        if (!this.detectionLocationType) {
          this.$message.error("请选择检测位置类型");
          return;
        }
        getDetectionLocationRow(this.itemsId, this.detectionLocationType)
          .then((res) => {
            this.form2.detectionLocations.push(...(res.data || []));
            this.form2.detectionLocations.sort(
              (a, b) =>
                a.positionType - b.positionType || a.groupNumber - b.groupNumber
            );
            this.dialogVisible = false;
            this.submitTestForm(2);
            this.bindMethod();
          })
          .catch(() => {});
      } else if (this.operType == "delete") {
        if (!this.detectionLocationType) {
          this.$message.error("请选择检测位置类型");
          return;
        }
        if (!this.groupNumber) {
          this.$message.error("请选择检测位置组");
          return;
        }
        this.form2.detectionLocations = this.form2.detectionLocations.filter(
          (item) =>
            item.groupNumber != this.groupNumber ||
            item.positionType != this.detectionLocationType
        );
        console.log(this.form2.detectionLocations);
        this.dialogVisible = false;
        this.submitTestForm(2);
        this.bindMethod();
      }
    },
    handleDetectionLocationTypeChange() {
      if (this.operType == "delete") {
        this.containsGroup = [];
        this.groupNumberList.forEach((it) => (it.label = it.text));
        this.form2.detectionLocations.forEach((item) => {
          if (item.positionType == this.detectionLocationType) {
            this.containsGroup.push(item.groupNumber);
            if (
              this.detectionLocationType == 4 ||
              this.detectionLocationType == 5
            ) {
              // 墙、点位
              const findRes = this.groupNumberList.find(
                (it) => it.value == item.groupNumber
              );
              if (findRes) findRes.label = item.positionName;
            }
          }
        });
        this.containsGroup = Array.from(new Set(this.containsGroup));
      }
    },
    handleDialogOpen() {
      this.handleDetectionLocationTypeChange();
    },
    handleDialogClosed() {
      this.detectionLocationType = 1;
      this.groupNumber = "";
    },
    handleOpenDragCanvas() {
      this.$refs.dragCanvasRefs.openDialog({
        imageJson: this.form.imageJson,
      });
    },
    handleConfirmDrag(data) {
      this.form = {
        ...this.form,
        ossId: data.ossId,
        imageJson: data.imageJson,
      };
      this.submitTestForm("form");
    },
    handleChangeImage(val) {
      this.submitTestForm("form");
    },
    isAllNull(rowNum) {
      if (rowNum == 24) {
        if (
          !this.form2.positionName_24 &&
          this.form2.positionName_24 !== 0 &&
          !this.form2.readoutValue_24_1 &&
          this.form2.readoutValue_24_1 !== 0 &&
          !this.form2.readoutValue_24_2 &&
          this.form2.readoutValue_24_2 !== 0 &&
          !this.form2.readoutValue_24_3 &&
          this.form2.readoutValue_24_3 !== 0 &&
          !this.form2.correctedAverage_24 &&
          this.form2.correctedAverage_24 !== 0 &&
          !this.form2.correctedValue_24 &&
          this.form2.correctedValue_24 !== 0 &&
          !this.form2.yearDoseValue_24 &&
          this.form2.yearDoseValue_24 !== 0
        ) {
          return true;
        }
      }
      if (rowNum == 25) {
        if (
          !this.form2.positionName_25 &&
          this.form2.positionName_25 !== 0 &&
          !this.form2.readoutValue_25_1 &&
          this.form2.readoutValue_25_1 !== 0 &&
          !this.form2.readoutValue_25_2 &&
          this.form2.readoutValue_25_2 !== 0 &&
          !this.form2.readoutValue_25_3 &&
          this.form2.readoutValue_25_3 !== 0 &&
          !this.form2.correctedAverage_25 &&
          this.form2.correctedAverage_25 !== 0 &&
          !this.form2.correctedValue_25 &&
          this.form2.correctedValue_25 !== 0 &&
          !this.form2.yearDoseValue_25 &&
          this.form2.yearDoseValue_25 !== 0
        ) {
          return true;
        }
      }
      if (rowNum == 26) {
        if (
          !this.form2.positionName_26 &&
          this.form2.positionName_26 !== 0 &&
          !this.form2.readoutValue_26_1 &&
          this.form2.readoutValue_26_1 !== 0 &&
          !this.form2.readoutValue_26_2 &&
          this.form2.readoutValue_26_2 !== 0 &&
          !this.form2.readoutValue_26_3 &&
          this.form2.readoutValue_26_3 !== 0 &&
          !this.form2.correctedAverage_26 &&
          this.form2.correctedAverage_26 !== 0 &&
          !this.form2.correctedValue_26 &&
          this.form2.correctedValue_26 !== 0 &&
          !this.form2.yearDoseValue_26 &&
          this.form2.yearDoseValue_26 !== 0
        ) {
          return true;
        }
      }
      if (rowNum == 27) {
        if (
          !this.form2.positionName_27 &&
          this.form2.positionName_27 !== 0 &&
          !this.form2.readoutValue_27_1 &&
          this.form2.readoutValue_27_1 !== 0 &&
          !this.form2.readoutValue_27_2 &&
          this.form2.readoutValue_27_2 !== 0 &&
          !this.form2.readoutValue_27_3 &&
          this.form2.readoutValue_27_3 !== 0 &&
          !this.form2.correctedAverage_27 &&
          this.form2.correctedAverage_27 !== 0 &&
          !this.form2.correctedValue_27 &&
          this.form2.correctedValue_27 !== 0 &&
          !this.form2.yearDoseValue_27 &&
          this.form2.yearDoseValue_27 !== 0
        ) {
          return true;
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../content.scss";
.protection-table {
  ::v-deep .el-input {
    width: 100%;
  }
}

::v-deep .dir-select.el-select > .el-input {
  height: 36px;
}
</style>
